#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "crypto/types.h"
#include "crypto/json.h"

int main()
{
    Json *json = JsonInit();
    JsonValue *jsonValue = (JsonValue *)malloc(sizeof(JsonValue));
    jsonValue->type = JSON_VALUE_TYPE_DOUBLE;
    jsonValue->value = malloc(sizeof(double));
    *(double *)(jsonValue->value) = 78.123;
    JsonPut(json, JsonItemInit("Weight", jsonValue));

    jsonValue = (JsonValue *)malloc(sizeof(JsonValue));
    jsonValue->type = JSON_VALUE_TYPE_LONG;
    jsonValue->value = malloc(sizeof(int64));
    *(int64 *)(jsonValue->value) = 17879386605;
    JsonPut(json, JsonItemInit("Phone", jsonValue));

    jsonValue = (JsonValue *)malloc(sizeof(JsonValue));
    jsonValue->type = JSON_VALUE_TYPE_STRING;
    jsonValue->value = malloc(sizeof(char) * 20);
    strcpy((char *)(jsonValue->value), "Su wenyang");
    JsonPut(json, JsonItemInit("Name", jsonValue));

    jsonValue = (JsonValue *)malloc(sizeof(JsonValue));
    jsonValue->type = JSON_VALUE_TYPE_ARRAY;

    JsonArray *jsonArray = JsonArrayInit();
    jsonArray->cap = 12;
    jsonArray->len = 12;
    jsonArray->type = JSON_VALUE_TYPE_DOUBLE;
    jsonArray->array = (double *)malloc(sizeof(double) * 12);
    for (int i = 0; i < 12; i++)
    {
        ((double *)jsonArray->array)[i] = i * 1012.213;
    }
    jsonValue->value = jsonArray;
    JsonPut(json, JsonItemInit("Salary", jsonValue));

    printf("%s\n", JsonString(json, NULL));
    free(json);
    return 0;
}